/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sgsmcan.Dao;

import com.sgsmcan.Entidad.Color;
import com.sgsmcan.Hibernate.HibernateUtil;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author user
 */
public class ColorDaoImpl extends HibernateDao<Color> implements ColorDao{ 

    @Override
    public List<Color> getColores() {
        List<Color> auxiliar = null;
        Session session = null;
        try{
            session = HibernateUtil.getSessionFactory().openSession();
            Criteria criteria = session.createCriteria(Color.class,"color");
            auxiliar = criteria.list();
        }catch(HibernateException e){
            throw  new HibernateException(e);
        }finally{
            if(session != null){
                session.close();
            }
        }
        return auxiliar;
    }

    @Override
    public Color getColor(Integer id) {
        Session session = null;
        try{
            session = HibernateUtil.getSessionFactory().openSession();
            Criteria criteria = session.createCriteria(Color.class,"color").add(Restrictions.eq("color.id",id));
            return (Color)criteria.uniqueResult();
        }catch(HibernateException e){
            throw  new HibernateException(e);
        }finally{
            if(session != null){
                session.close();
            }
        }
    }
    
}
